GtkProgressBar: Add style classes for edges
authorMatthias Clasen <mclasen@redhat.com>
Sat, 19 Jul 2014 04:40:09 +0000 (00:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 19 Jul 2014 04:40:09 +0000 (00:40 -0400)
Add left/right/top/bottom style classes according to which edge(s)
of the progressbar the progress is adjacent to. Only for a fraction
of 1.0 will we set more than one edge.

gtk/gtkcolorswatch.c
gtk/gtkprogressbar.c

index 2f97f94fc76a47db6066afcadcf17c1f122be2bb..7af895661b87841bc2e4d49aa825064f7662fbae 100644 (file)
@@ -170,8 +170,7 @@ swatch_draw (GtkWidget *widget,
   else
     _gtk_theming_background_render (&background, cr);
 
-  gtk_render_frame (context, cr,
-                    0, 0, width, height);
+  gtk_render_frame (context, cr, 0, 0, width, height);
 
   if (gtk_widget_has_visible_focus (widget))
     {
index 65399214a639b13f5516d12a2d2283190c3c4e3a..5cdda739aecb5617242cfa64ffe5b6e6ee321b4c 100644 (file)
@@ -759,23 +759,31 @@ gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
   state = gtk_widget_get_state_flags (widget);
   gtk_style_context_get_padding (context, state, &padding);
 
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
+
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       gtk_progress_bar_get_activity (pbar, orientation, &area.x, &area.width);
       area.y = y + padding.top;
       area.height = height - padding.top - padding.bottom;
+      if (pbar->priv->activity_pos <= 0.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+      else if (pbar->priv->activity_pos >= 1.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
     }
   else
     {
       gtk_progress_bar_get_activity (pbar, orientation, &area.y, &area.height);
       area.x = x + padding.left;
       area.width = width - padding.left - padding.right;
+      if (pbar->priv->activity_pos <= 0.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
+      else if (pbar->priv->activity_pos >= 1.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
     }
 
-  gtk_style_context_save (context);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PULSE);
-
   gtk_render_activity (context, cr, area.x, area.y, area.width, area.height);
 
   gtk_style_context_restore (context);
@@ -805,6 +813,9 @@ gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
   state = gtk_widget_get_state_flags (widget);
   gtk_style_context_get_padding (context, state, &padding);
 
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
+
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       area.width = amount;
@@ -815,6 +826,11 @@ gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
         area.x = x + padding.left;
       else
         area.x = width - amount - padding.right;
+
+      if (!inverted || gtk_progress_bar_get_fraction (pbar) == 1.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+      if (inverted || gtk_progress_bar_get_fraction (pbar) == 1.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
     }
   else
     {
@@ -826,10 +842,12 @@ gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
         area.y = y + padding.top;
       else
         area.y = height - amount - padding.bottom;
-    }
 
-  gtk_style_context_save (context);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR);
+      if (!inverted || gtk_progress_bar_get_fraction (pbar) == 1.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
+      if (inverted || gtk_progress_bar_get_fraction (pbar) == 1.0)
+        gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
+    }
 
   gtk_render_activity (context, cr, area.x, area.y, area.width, area.height);